<template>
  <div class="answer">
    <div class="answer_header">问卷调查</div>
    <div class="answer_box" v-for="item in data" :key="item.id" @click="goAnswerSheetForm(item)">
      <div class="answer_box_top">
        <span>{{ item.questionnaire_title }}</span>
        <span :class="item.status == 0 ? 'cancel_tag' : 'success_tag'">
          {{ item.status == 0 ? "未提交" : "已提交" }}
        </span>
      </div>
      <div class="answer_box_center">{{ item.company }}</div>
      <div>{{ item.update_time }}</div>
      <div class="answer_box_btn">
        {{ item.status == 0 ? "继续填写" : "查看" }}
      </div>
    </div>
    <div>
      <van-button
        block
        size="small"
        type="danger"
        class="request-btn"
        @click="handleCreateDemand"
      >
        填写新问卷
      </van-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useRouter } from 'vue-router'
import { getMyQuestionnaireList } from "@/api/index";
import { getToken } from '@/service/cookie'

const code = getToken('code')
const router = useRouter()
const data: any = ref([
  {
    id: 1,
    title: "2024年年报走访工作开展及信息采集",
    company: "深圳市橙美科技有限公司",
    time: "2024-05-16 13:01:15",
    status: 0,
  },
  {
    id: 2,
    title: "2024年年报走访工作开展及信息采集",
    company: "深圳市橙美科技有限公司",
    time: "2024-05-16 13:01:15",
    status: 1,
  },
]);

const getMyQuestionList = async() => {
    const res = await getMyQuestionnaireList()
    console.log(res)
    data.value = res
}

getMyQuestionList()

const handleCreateDemand = () => {
  router.push({path: '/answerSheet/form'})
}; 

const goAnswerSheetForm = (val: any) => {
    const params = {
        id: val.id,
        status: val.status
    }
    router.push({path: '/answerSheet/form', query: params})
}
</script>

<style lang="less" scoped>
.answer {
  .answer_header {
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
  }

  .answer_box {
    background: #fff;
    padding: 10px 10px 15px 10px;
    border-radius: 10px;
    font-size: 14px;
    margin: 0 20px 20px 20px;

    .answer_box_top {
      margin: 10px 0 5px 0;
      line-height: 1.4;

      .cancel_tag {
        background: #f96257;
        color: #fff;
        padding: 1px 4px;
        border-radius: 5px;
        font-size: 11px;
        margin-left: 5px;
      }

      .success_tag {
        background: #2c76ed;
        color: #fff;
        padding: 1px 4px;
        border-radius: 5px;
        font-size: 11px;
        margin-left: 5px;
      }
    }

    .answer_box_center {
      margin-bottom: 10px;
    }

    .answer_box_btn {
      background: #2c76ed;
      color: #fff;
      text-align: center;
      padding: 10px 0;
      margin-top: 10px;
      border-radius: 10px;
      cursor: point;
    }
  }

  .request-btn {
    font-size: 16px;
    border: none;
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    width: 149px;
    height: 44px;
    background: #2c76ed;
    box-shadow: 0px 2px 2px 0px #0e9cd6;
    border-radius: 5px;
  }
}

@media (min-width: 750px) {
  .answer {
    .answer_header {
      width: 100%;
      height: 50px;
      line-height: 50px;
      text-align: center;
    }

    .answer_box {
      background: #fff;
      padding: 10px;
      border-radius: 10px;
      font-size: 14px;
      margin: 0 20px 20px 20px;

      .answer_box_top {
        margin: 10px 0 5px 0;
        line-height: 1.4;

        .cancel_tag {
          background: #f96257;
          color: #fff;
          padding: 1px 4px;
          border-radius: 5px;
          font-size: 11px;
          margin-left: 5px;
        }

        .success_tag {
          background: #2c76ed;
          color: #fff;
          padding: 1px 4px;
          border-radius: 5px;
          font-size: 11px;
          margin-left: 5px;
        }
      }

      .answer_box_center {
        margin-bottom: 10px;
      }

      .answer_box_btn {
        background: #2c76ed;
        color: #fff;
        text-align: center;
        padding: 10px 0;
        margin-top: 10px;
        border-radius: 10px;
      }
    }

    .request-btn {
      font-size: 16px;
      border: none;
      position: fixed;
      bottom: 100px;
      left: 50%;
      transform: translateX(-50%);
      z-index: 20;
      width: 149px;
      height: 44px;
      background: #2c76ed;
      box-shadow: 0px 2px 2px 0px #0e9cd6;
      border-radius: 5px;
    }
  }
}
</style>
